TryGetItem Method

Wintellect PowerCollections

Collapse imageExpand ImageCollapseAll imageExpandAll imageDropDown imageDropDownHover imageCopy imageCopyHover image
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Determines if this set contains an item equal to item, according to the comparison mechanism that was used when the set was created. The set is not changed.

If the set does contain an item equal to item, then the item from the set is returned.

Namespace: Wintellect.PowerCollections
Assembly:  PowerCollections (in PowerCollections.dll)

Syntax

C#
public bool TryGetItem(
	T item,
	out T foundItem
)
Visual Basic (Declaration)
Public Function TryGetItem ( _
	item As T, _
	<OutAttribute> ByRef foundItem As T _
) As Boolean
Visual C++
public:
bool TryGetItem (
	T item, 
	[OutAttribute] T% foundItem
)

Parameters

item
T
The item to search for.
foundItem
T%
Returns the item from the set that was equal to item.

Return Value

True if the set contains item. False if the set does not contain item.

Remarks

Searching the set for an item takes time O(log N), where N is the number of items in the set.

Examples

In the following example, the set contains strings which are compared in a case-insensitive manner.
 Copy imageCopy Code
            OrderedSet<string> set = new OrderedSet<string>(StringComparer.CurrentCultureIgnoreCase);
            set.Add("HELLO");
            string s;
            bool b = set.TryGetItem("Hello", out s);   // b receives true, s receives "HELLO".
            

See Also